package com.ruoyi.web.controller.tongban;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.tongban.domain.AppletsQrCode;
import com.ruoyi.tongban.service.IAppletsQrCodeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 小程序二维码Controller
 * 
 * @author caiyanshan
 * @date 2021-03-10
 */
@RestController
@RequestMapping("/tongban/qrcode")
public class AppletsQrCodeController extends BaseController
{
    @Autowired
    private IAppletsQrCodeService appletsQrCodeService;

    /**
     * 查询小程序二维码列表
     */
    @PreAuthorize("@ss.hasPermi('tongban:qrcode:list')")
    @GetMapping("/list")
    public TableDataInfo list(AppletsQrCode appletsQrCode)
    {
        startPage();
        List<AppletsQrCode> list = appletsQrCodeService.selectAppletsQrCodeList(appletsQrCode);
        return getDataTable(list);
    }
    
    @GetMapping("/institutinonQrcode")
    public AjaxResult institutinonQrcode(@RequestParam Long institutionId) {
        return AjaxResult.success(appletsQrCodeService.getQrCodeByInstitutionId(institutionId));
    }

    /**
     * 导出小程序二维码列表
     */
    @PreAuthorize("@ss.hasPermi('tongban:qrcode:export')")
    @Log(title = "小程序二维码", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(AppletsQrCode appletsQrCode)
    {
        List<AppletsQrCode> list = appletsQrCodeService.selectAppletsQrCodeList(appletsQrCode);
        ExcelUtil<AppletsQrCode> util = new ExcelUtil<AppletsQrCode>(AppletsQrCode.class);
        return util.exportExcel(list, "qrcode");
    }

    /**
     * 获取小程序二维码详细信息
     */
    @PreAuthorize("@ss.hasPermi('tongban:qrcode:query')")
    @GetMapping(value = "/{appletsQrcodeId}")
    public AjaxResult getInfo(@PathVariable("appletsQrcodeId") Long appletsQrcodeId)
    {
        return AjaxResult.success(appletsQrCodeService.selectAppletsQrCodeById(appletsQrcodeId));
    }

    /**
     * 新增小程序二维码
     */
    @PreAuthorize("@ss.hasPermi('tongban:qrcode:add')")
    @Log(title = "小程序二维码", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AppletsQrCode appletsQrCode)
    {
        return toAjax(appletsQrCodeService.insertAppletsQrCode(appletsQrCode));
    }

    /**
     * 修改小程序二维码
     */
    @PreAuthorize("@ss.hasPermi('tongban:qrcode:edit')")
    @Log(title = "小程序二维码", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AppletsQrCode appletsQrCode)
    {
        return toAjax(appletsQrCodeService.updateAppletsQrCode(appletsQrCode));
    }

    /**
     * 删除小程序二维码
     */
    @PreAuthorize("@ss.hasPermi('tongban:qrcode:remove')")
    @Log(title = "小程序二维码", businessType = BusinessType.DELETE)
	@DeleteMapping("/{appletsQrcodeIds}")
    public AjaxResult remove(@PathVariable Long[] appletsQrcodeIds)
    {
        return toAjax(appletsQrCodeService.deleteAppletsQrCodeByIds(appletsQrcodeIds));
    }
}
